//
//  MBShippingPopView.m
//  MemberBusiness-ios
//
//  Created by cherry pu on 2018/4/26.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBShippingPopView.h"
#import "MBShippingTableViewCell.h"


@interface MBShippingPopView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSArray* dataArray;

@end

@implementation MBShippingPopView

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        UITableView* tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self).insets(UIEdgeInsetsZero);
        }];
    }
    return self;
}

-(NSArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [MBLoginUserModelArchieveTool shippingUnAchieveFromFile];
    }
    return _dataArray;
}

#pragma mark - UITableView Delegate DataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identify = NSStringFromClass([self class]);
    
    MBShippingTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (cell == nil) {
        cell = [[MBShippingTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
    }
    cell.shippingModel = self.dataArray[indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [UIView lf_sizeFromIphone6:26];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.chooseShippModel = self.dataArray[indexPath.row];
}



@end
